package br.com.view;

//todos os scripts vem nessa class.
public class FabricaScripts {
	public static String addLocalscrpts(){
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\" src=\"./js/jquery-1.2.6.pack.js\"></script>\n");
		return sb.toString();
	}
	
	public static String mascaras() {
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\" src=\"./js/jquery.maskedinput-1.1.2.js\"></script>\n");
		sb.append("<script type=\"text/javascript\">  \n");
		sb.append("$(document).ready(function(){ \n ");
		sb.append("$(function(){\n");
		sb.append("$.mask.addPlaceholder(\"~\",\"[+-]\");\n");
		sb.append("$(\"#telefone\").mask(\"(99) 9999-9999\");\n");
		sb.append("$(\"#celular\").mask(\"(99) 9999-9999\");\n");
		sb.append("$(\"#fax\").mask(\"(99) 9999-9999\");\n");
		sb.append("$(\"#cep\").mask(\"99999-999\");\n");
		sb.append("$(\"#data\").mask(\"99/99/9999\");\n");
		sb.append("$(\"#cpf\").mask(\"999.999.999-99\");\n");
		sb.append("$(\"#cnpj\").mask(\"99.999.999/9999-99\");\n");
		sb.append("});\n");
		sb.append("});\n");
		sb.append("</script>\n");
		return sb.toString();
	}
	public static String tableBox(){
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\" src=\"./js/jquery-1.5.1.js\"></script>\n");
		sb.append("<script>\n"); 
		sb.append("$(document).ready(function(){\n");
		sb.append("$(\"a.tab\").click(function () {\n");
		sb.append("$(\".active\").removeClass(\"active\");\n");
		sb.append("$(this).addClass(\"active\");\n");
		sb.append("$(\".content\").slideUp();\n");
		sb.append("var content_show = $(this).attr(\"title\");\n");
		sb.append("$(\"#\"+content_show).slideDown();\n");
		sb.append("});\n");
		sb.append("});\n");
		sb.append("</script>\n");
		return sb.toString();
	}
	public static String apresentarOcultarDiv(){
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\" src=\"./js/jquery-1.3.js\"></script>\n");
		sb.append("<script type=\"text/javascript\">\n");
		sb.append("jQuery.fn.toggleText = function(a,b) {\n");
		sb.append("return   this.html(this.html().replace(new RegExp(\"(\"+a+\"|\"+b+\")\"),function(x){return(x==a)?b:a;}));\n");
		sb.append("}\n");

		sb.append("$(document).ready(function(){\n");
		//'<span>Apresentar</span>'
		sb.append("$('.tgl').before(\""+FabricaHtml.criarDiv("", "Apresentar")+"\");\n");
		sb.append("$('.tgl').css('display', 'none')\n");
		sb.append("$('span', '#box-toggle').click(function() {\n");
		sb.append("$(this).next().slideToggle('slow')\n");
		sb.append(".siblings('.tgl:visible').slideToggle('fast');\n");
		// aqui come�a o funcionamento do plugin
		sb.append("$(this).toggleText('Revelar','Esconder')\n");
		sb.append(".siblings('span').next('.tgl:visible').prev()\n");
		sb.append(".toggleText('Revelar','Esconder')\n");
		sb.append("});\n");
		sb.append("})\n");
		sb.append("</script>\n");
		return sb.toString();
	}
	public static String preencheComboBox(){
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\" src=\"./js/jquery-1.3.2.js\"></script>\n");
		sb.append("<script type=\"text/javascript\">\n");
		sb.append("$(document).ready(function(){\n");
		sb.append("$('#estados').change(function(){\n");
		sb.append("$('#cidades').load('cidades?estados='+$('#estados').val() );\n");
		sb.append("});\n");
		sb.append("});\n");
		sb.append("</script>\n");
		return sb.toString();
	}
	//fun��o para teste
	public static String preencheFormTest(){
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\" src=\"./js/jquery-1.3.2.js\"></script>\n");
		sb.append("<script type=\"text/javascript\">\n");
		sb.append("$(document).ready(function(){\n");
		sb.append("$('#botaoRecibo').change(function(){\n");
		sb.append("$('#AdicionaReciboServlet').load('recibo?botaoRecibo='+$('#botaoRecibo').val() );\n");
		sb.append("});\n");
		sb.append("});\n");
		sb.append("</script>\n");
		return sb.toString();
	}
	
	//metodo para gerar script de model (janelas)
	public static String modelWindow(){
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\" src=\"./js/jqueryModel.js\"></script> \n");
		sb.append("<script type=\"text/javascript\">\n");
		sb.append("$(document).ready(function() {\n");
		sb.append("$('a[name=modal]').click(function(e) {\n");
		sb.append("e.preventDefault();\n");
		sb.append("var id = $(this).attr('href');\n");
		sb.append("var maskHeight = $(document).height();\n");
		sb.append("var maskWidth = $(window).width();\n");
		sb.append("$('#mask').css({'width':maskWidth,'height':maskHeight});\n");
		sb.append("$('#mask').fadeIn(1000);\n	");
		sb.append("$('#mask').fadeTo(\"slow\",0.8);\n");	
				//Get the window height and width
		sb.append("var winH = $(window).height();\n");
		sb.append("var winW = $(window).width();\n");
		              
		sb.append("$(id).css('top',  winH/2-$(id).height()/2);\n");
		sb.append("$(id).css('left', winW/2-$(id).width()/2);\n");
		sb.append("$(id).fadeIn(2000); \n");
		sb.append("});\n");
		sb.append("$('.window .close').click(function (e) {\n");
		sb.append("e.preventDefault();\n");
		sb.append("$('#mask').hide();\n");
		sb.append("$('.window').hide();\n");
		sb.append("});	\n	");
		sb.append("$('#mask').click(function () {\n");
		sb.append("$(this).hide();\n");
		sb.append("$('.window').hide();\n");
		sb.append("});\n");
		sb.append("});\n");
		sb.append("</script>\n");
		return sb.toString();
	}
	public static String divsArredond(String nomeDiv){
		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\">\n");
		//sb.append("$(document).ready(function(){\n");
		//sb.append("$('."+nomeDiv+"').corner({\n");
		//sb.append("tl: { radius: 10 },\n");
		//sb.append(" tr: { radius: 10 },\n");
		//sb.append("bl: { radius: 10 },\n");
		//sb.append("br: { radius: 10 }\n");
		//sb.append("});\n");

		//sb.append("$('."+nomeDiv+"').corner(\"keep\");\n");
		//sb.append("});\n");
		sb.append("</script>\n");
		/*sb.append("<script>\n");
		sb.append("$(function() {\n");
		sb.append("$( \"input:submit, a, button\", \"#"+nomeDiv+"\" ).button();\n");
		sb.append("$( \"a\", \"#"+nomeDiv+"\" ).click(function() { return false; });\n");
		sb.append("});\n");
		sb.append("</script>\n");*/
		return sb.toString();
	}
	public static String alterDiv(){
		StringBuilder sb = new StringBuilder();
		//sb.append(cssErro());
		//sb.append("<script type=\"text/javascript\">\n");
		//sb.append(usuarioApressado());
		/*sb.append("$(document).ready(function(){\n");
		sb.append("$('#perfil').click(function(){\n");
		sb.append("$('.apresenteForm').load(\"perfil\", function(){\n$(\"#data\").mask(\"99/99/9999\"); \n"+validatForm()+"\n});\n");
		sb.append("});\n");
		sb.append("});\n");
		sb.append("$(document).ready(function(){\n");
		sb.append("$('#login').click(function(){\n");
		sb.append("$('.apresenteForm').load(\"login\");\n");
		sb.append("});\n");
		sb.append("});\n");
		sb.append("</script>\n");
		*/return sb.toString();
	}
	public static String forms(){
		StringBuilder sb = new StringBuilder();
		// Quando carregado a p�gina
		sb.append("<script type=\"text/javascript\">\n");
		sb.append("$(function($) {\n");
		    // Quando enviado o formul�rio
			sb.append("$('#LoginServlet').submit(function()\n");
		        // Enviando informa��es do formul�rio via AJAX
			sb.append("$(this).ajaxSubmit(function(resposta) {\n");
		            // Se n�o retornado nenhum erro
			sb.append("if (resposta)\n");
		                // Exibimos a mensagem de erro
			sb.append("$('div.mensagem-erro').html(resposta);\n");
		    sb.append("});\n");
		        // Retornando false para que o formul�rio n�o envie as 
		        //informa��es da forma convencional
		    sb.append("return false;\n");
		    sb.append("});\n");
		    sb.append("});\n");
		    sb.append("</script>\n");
		return sb.toString();
	}
	public static String usuarioApressado(){
		StringBuilder sb = new StringBuilder();
		sb.append("$(function() {\n");
		sb.append("$(\"form\").submit(function() {\n");
		sb.append("if (minhaFuncao() == true) {\n");
		// ReadOnly em todos os inputs
		sb.append("$(\"input\", this).attr(\"readonly\", true);\n");
		// Desabilita os submits
		sb.append("$(\"input[type='submit'],input[type='image']\", this).attr(\"disabled\", true);\n");
		sb.append("return true;\n");
		sb.append("} else {\n");
		sb.append("return false;\n");
		sb.append("}\n");
		sb.append("});\n");
		sb.append("});\n");
		return sb.toString();
	}
	public static String validatForm(){
		StringBuilder sb = new StringBuilder();
		//sb.append("$(document).ready( function() {\n");
		sb.append("$(\"#CadastroPerfilLogin\").validate({\n");
		// Define as regras
		sb.append("rules:{\n");
		sb.append("nome:{\n");
		// campoNome ser� obrigat�rio (required) e ter� tamanho m�nimo (minLength)
		sb.append("required: true, minlength: 4\n");
		sb.append("},\n");
		//sb.append("data:{\n");
		// campoEmail ser� obrigat�rio (required) e precisar� ser um e-mail v�lido (email)
		//sb.append("required: true,\n");
		//sb.append(" dateBR: true\n");
		//sb.append("},\n");
		sb.append("email:{\n");
		// campoMensagem ser� obrigat�rio (required) e ter� tamanho m�nimo (minLength)
		sb.append("required: true, email: true\n");
		sb.append("},\n");
		sb.append("senha:{\n");
		// campoMensagem ser� obrigat�rio (required) e ter� tamanho m�nimo (minLength)
		sb.append("required: true, minlength: 6\n");
		sb.append("}\n");
		sb.append("},\n");
		// Define as mensagens de erro para cada regra
		sb.append("messages:{\n");
		sb.append("nome:{\n");
		sb.append("required: \"Digite o seu nome\",\n");
		sb.append("minLength: \"O seu nome deve conter no m�nimo 4 caracteres\"\n");
		sb.append("},\n");
		sb.append("data:{\n");
		sb.append("required: \"Digite uma data valida\",\n");
		sb.append("dateBR: \"Data incompleta, preencha corretamente!\"\n");
		sb.append("},\n");
		sb.append("email:{\n");
		sb.append("required: \"Formato de e-mail invalido!\",\n");
		sb.append("email: \"Digite um e-mail v�lido\"\n");
		sb.append("},\n");
		sb.append("senha:{\n");
		sb.append("required: \"Defina sua senha!\",\n");
		sb.append("minLength: \"Digite uma senha com no minimo 6 caracteres!\"\n");
		sb.append("}\n");
		sb.append("}\n");
		sb.append("});\n");
		//sb.append("});\n");
		return sb.toString();
	}
	public static String cssErro(){
		StringBuilder sb = new StringBuilder();
		sb.append("<style type=\"text/css\">\n");
		sb.append("label.error { float: none; color: red; margin: 0 1px 0 0; vertical-align: top; font-size: 10px }\n");
		sb.append(".submit { margin-top: 1px; }\n");
		sb.append("em { font-weight: bold; padding-right: 1px; vertical-align: top; }\n");
		sb.append("</style>\n");
		return sb.toString();
	}
	
	public static String cssJquery(){
		StringBuilder sb = new StringBuilder();
		sb.append("<style type=\"text/css\">\n");
		/*demo page css*/
		sb.append(".demoHeaders { margin-top: 2em; }\n");
		sb.append("#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}\n");
		sb.append("#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}\n");
		sb.append("ul#icons {margin: 0; padding: 0;}\n");
		sb.append("ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}\n");
		sb.append("ul#icons span.ui-icon {float: left; margin: 0 4px;}\n");
		sb.append("</style>\n");
		
		sb.append("<style>\n");
		sb.append("label, input { display:block; }\n");
		sb.append("input.text { margin-bottom:10px; width:95%; padding: .4em; }\n");
		sb.append("fieldset { padding:0; border:0; margin-top:25px; }\n");
		sb.append("h1 { font-size: 1.2em; margin: .6em 0; }\n");
		sb.append("div#users-contain { width: 350px; margin: 20px 0; }\n");
		sb.append("div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }\n");
		sb.append("div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }\n");
		sb.append(".ui-dialog .ui-state-error { padding: .3em; }\n");
		sb.append(".validateTips { border: 1px solid transparent; padding: 0.3em; }\n");
		sb.append("</style>\n");
		return sb.toString();
	}
	
	public static String jqueryFuncoes(){
		StringBuilder sb = new StringBuilder();
		
		//cria forms com campos
		sb.append("<script>\n");
		sb.append("$(function() {\n");
		sb.append("	// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!\n");
		sb.append("	$( \"#dialog:ui-dialog\" ).dialog( \"destroy\" );\n");
			
		sb.append("	var name = $( \"#name\" ),\n");
		sb.append("		email = $( \"#email\" ),\n");
		sb.append("		password = $( \"#password\" ),\n");
		sb.append("		allFields = $( [] ).add( name ).add( email ).add( password ),\n");
		sb.append("		tips = $( \".validateTips\" );\n");

		sb.append("	function updateTips( t ) {\n");
		sb.append("		tips\n");
		sb.append("			.text( t )\n");
		sb.append("			.addClass( \"ui-state-highlight\" );\n");
		sb.append("		setTimeout(function() {\n");
		sb.append("			tips.removeClass( \"ui-state-highlight\", 1500 );\n");
		sb.append("		}, 500 );\n");
		sb.append("	}\n");

		sb.append("	function checkLength( o, n, min, max ) {\n");
		sb.append("		if ( o.val().length > max || o.val().length < min ) {\n");
		sb.append("			o.addClass( \"ui-state-error\" );\n");
		sb.append("			updateTips( \"Length of \" + n + \" must be between \" +\n");
		sb.append("				min + \" and \" + max + \".\" );\n");
		sb.append("			return false;\n");
		sb.append("		} else {\n");
		sb.append("			return true;\n");
		sb.append("		}\n");
		sb.append("	}\n");

		sb.append("	function checkRegexp( o, regexp, n ) {\n");
		sb.append("		if ( !( regexp.test( o.val() ) ) ) {\n");
		sb.append("			o.addClass( \"ui-state-error\" );\n");
		sb.append("			updateTips( n );\n");
		sb.append("			return false;\n");
		sb.append("		} else {\n");
		sb.append("			return true;\n");
		sb.append("		}\n");
		sb.append("	}\n");
		
		sb.append("	$( \"#dialog-form\" ).dialog({\n");
		sb.append("		autoOpen: false,\n");
		sb.append("		height: 300,\n");
		sb.append("		width: 350,\n");
		sb.append("		modal: true,\n");
		sb.append("		buttons: {\n");
		sb.append("			\"Create an account\": function() {\n");
		sb.append("				var bValid = true;\n");
		sb.append("				allFields.removeClass( \"ui-state-error\" );\n");

		sb.append("				bValid = bValid && checkLength( name, \"username\", 3, 16 );\n");
		sb.append("				bValid = bValid && checkLength( email, \"email\", 6, 80 );\n");
		sb.append("				bValid = bValid && checkLength( password, \"password\", 5, 16 );\n");

		sb.append("				bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, \"Username may consist of a-z, 0-9, underscores, begin with a letter.\" );\n");
								// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
		sb.append("				bValid = bValid && checkRegexp( email, /^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?$/i, \"eg. ui@jquery.com\" );\n");
		sb.append("				bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, \"Password field only allow : a-z 0-9\" );\n");

		sb.append("				if ( bValid ) {\n");
		sb.append("					$( \"#users tbody\" ).append( \"<tr>\" +\n");
		sb.append("						\"<td>\" + name.val() + \"</td>\" + \n");
		sb.append("						\"<td>\" + email.val() + \"</td>\" +\n"); 
		sb.append("						\"<td>\" + password.val() + \"</td>\" +\n");
		sb.append("					\"</tr>\" ); \n");
		sb.append("					$( this ).dialog( \"close\" );\n");
		sb.append("				}\n");
		sb.append("			},\n");
		sb.append("			Cancel: function() {\n");
		sb.append("				$( this ).dialog( \"close\" );\n");
		sb.append("			}\n");
		sb.append("		},\n");
		sb.append("		close: function() {\n");
		sb.append("			allFields.val( \"\" ).removeClass( \"ui-state-error\" );\n");
		
		sb.append("		}\n");
		sb.append("	});\n");

		sb.append("	$( \"#create-user\" )\n");
		sb.append("		.button()\n");
		sb.append("		.click(function() {\n");
		sb.append("			$( \"#dialog-form\" ).dialog( \"open\" );\n");
		sb.append("		});\n");
		sb.append("});\n");
		sb.append("</script>\n");
		
		
		//------------------inicio que funciona
		sb.append("<script type=\"text/javascript\">\n");
		sb.append("$(function(){\n");

			// Accordion
		sb.append("	$(\"#accordion\").accordion({ header: \"h3\" });\n");
			// Tabs
		sb.append("	$('#tabs').tabs();\n");
		
		sb.append("	$('#tab').tabs();\n");



			// Dialog			
		sb.append("	$('#dialog').dialog({\n");
		sb.append("		autoOpen: false,\n");
		sb.append("		width: 600,\n");
		sb.append("		buttons: {\n");
		sb.append("			\"Ok\": function() {\n"); 
		sb.append("				$(this).dialog(\"close\");\n"); 
		sb.append("			}, \n");
		sb.append("			\"Cancel\": function() {\n"); 
		sb.append("				$(this).dialog(\"close\");\n"); 
		sb.append("			} \n");
		sb.append("		}\n");
		sb.append("	});\n");
			
			// Dialog Link
		sb.append("	$('#dialog_link').click(function(){\n");
		sb.append("		$('#dialog').dialog('open');\n");
		sb.append("		return false;\n");
		sb.append("	});\n");

			// Datepicker
		sb.append("	$('#datepicker').datepicker({\n");
		sb.append("		inline: true\n");
		sb.append("	});\n");
			
			// Slider
		sb.append("	$('#slider').slider({\n");
		sb.append("		range: true,\n");
		sb.append("		values: [17, 67]\n");
		sb.append("	});\n");
			
			// Progressbar
		sb.append("	$(\"#progressbar\").progressbar({\n");
		sb.append("		value: 20\n"); 
		sb.append("	});\n");
			
			//hover states on the static widgets
		sb.append("	$('#dialog_link, ul#icons li').hover(\n");
		sb.append("		function() { $(this).addClass('ui-state-hover'); }, \n");
		sb.append("		function() { $(this).removeClass('ui-state-hover'); }\n");
		sb.append("	);\n");
			
		sb.append("});\n");
		sb.append("</script>\n");
		
		return sb.toString();
	}
	
}
